/*
 * 创建日期 2005-10-31
 *
 * 更改所生成文件模板为
 * 窗口 > 首选项 > Java > 代码生成 > 代码和注释
 */
package com.vanda.report.dp;

import java.util.List;

import com.vanda.report.ReportException;
import com.vanda.report.ReportGroupRow;
import com.vanda.report.Validation;

/**
 * @author wkf5985
 *
 * 更改所生成类型注释的模板为
 * 窗口 > 首选项 > Java > 代码生成 > 代码和注释
 */
public class CleanRepeatedElement extends AggregationElement {

	/* 
	 * 校验属性
	 * @see com.vanda.report.element.Element#validator()
	 */
	public void validator() throws ReportException {
		Validation.checkRequired("MaxElement", "field", super.getField());
	}

	/* 
	 * 清除重复的信息
	 * @see com.vanda.report.dp.AggregationElement#aggregate(java.util.List, int, int, java.lang.String[])
	 */
	public Object[] aggregate(
		List beanList,
		int start,
		int end,
		String[] property)
		throws ReportException {

		//如果只有一条记录或者为空,则直接返回
		if (start >= end - 1) {
			return null;
		}

		try {
			boolean bFirst = true;
			//从第二条开始清除(应该是除掉ReportGroupRow)
			for (int i = start ; i < end; i++) {
				Object temp = beanList.get(i);
				if(temp instanceof ReportGroupRow){
					continue;
				}
				
				if(bFirst == false){
					for (int j = 0; j < property.length; j++) {
						super.setProperty(temp, property[j], null);
					}
				}else{
					//第一行不做clean
					bFirst = false;
				}


			}
		} catch (Exception e) {
			throw new ReportException(e);
		}

		return null;
	}

	/**
	 * 是否新增行,false-不新增
	 */
	protected boolean isCreateRecord() {
		return false;
	}
}
